Skip to content

Conversation

@joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Sep 6, 2025

<!--

## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes"

If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000):

## Notes for the reviewer

Anything important to call out? Be sure to also clarify these in your comments.

## How to test

Unit tests, playground, etc.

-->
[Playground] Feature: Add AI Chat Context Options Toggle

## Notes for the reviewer

This PR introduces a new UI bar in the AI chat playground that allows users to dynamically configure context options (`wallet address`, `chain IDs`, and `auto execute transactions`) for the `/ai/chat` API endpoint.

The changes include:
*   Updating `NebulaContext` type and `promptNebula` API call to support `auto_execute_transactions`.
*   Adding state management for user-defined context options in `ChatPageContent.tsx`.
*   Creating and integrating a `ContextOptionsBar` component for user input.
*   The `contextFilters` logic now prioritizes user-provided values for `walletAddress` and `chainIds`, and includes the `autoExecuteTransactions` flag.

## How to test

1.  Navigate to the AI chat playground (`/ai`).
2.  Observe the new "Context Options" bar above the chat input.
3.  Enter a wallet address (e.g., `0x123...`).
4.  Enter comma-separated chain IDs (e.g., `1, 8453`).
5.  Toggle the "Auto Execute Transactions" checkbox on/off.
6.  Send a chat message.
7.  Verify in the network tab that the `/ai/chat` request body includes the `context` object with the values you entered in the UI for `from`, `chain_ids`, and `auto_execute_transactions`.

Slack Thread

Open in Cursor Open in Web

PR-Codex overview

This PR introduces enhancements to the ChatPageContent component, adding user-configurable options for wallet address, chain IDs, and auto-execution of transactions. It also implements a new ContextOptionsBar component to facilitate these configurations.

Detailed summary

  • Added autoExecuteTransactions property to NebulaSwapData.
  • Updated wallet address handling in the chat API to use from and auto_execute_transactions.
  • Introduced state variables for user-configurable options in ChatPageContent.
  • Created ContextOptionsBar component for user inputs (wallet address, chain IDs, auto-execute).
  • Integrated ContextOptionsBar into the chat interface, allowing real-time updates.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added a Context Options bar to set Wallet Address, Chain IDs, and toggle Auto Execute Transactions in chat.
    • Chat requests now include the Auto Execute Transactions preference.
  • Improvements

    • Chain IDs input validates and accepts only numeric values.
    • Remembers last-used Chain IDs for quicker setup on return.
    • Context options available in both empty state and active chats for easy adjustments.

This commit introduces the ability to specify whether transactions should be automatically executed within the Nebula context. This provides more control over the AI's interaction with the blockchain.

Co-authored-by: joaquim.verges <[email protected]>
@cursor
Copy link

cursor bot commented Sep 6, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@changeset-bot
Copy link

changeset-bot bot commented Sep 6, 2025

⚠️ No Changeset found

Latest commit: ec92a36

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Sep 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
thirdweb_playground Canceled Canceled Sep 6, 2025 0:52am
4 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
docs-v2 Skipped Skipped Sep 6, 2025 0:52am
nebula Skipped Skipped Sep 6, 2025 0:52am
thirdweb-www Skipped Skipped Sep 6, 2025 0:52am
wallet-ui Skipped Skipped Sep 6, 2025 0:52am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 6, 2025

Walkthrough

API and UI changes add an auto-execute flag to Nebula context, expose user-editable wallet/chain/auto-execute controls in the chat UI, and adjust the API payload to rename wallet_addressfrom (sourced from context.walletAddress) while including auto_execute_transactions.

Changes

Cohort / File(s) Summary
API client: payload field rename & auto-execute
apps/playground-web/src/app/ai/api/chat.ts
When sending prompts, maps context.walletAddress to from (replacing prior wallet_address) and adds boolean auto_execute_transactions set to `params.context.autoExecuteTransactions
Types: extend NebulaContext
apps/playground-web/src/app/ai/api/types.ts
Adds optional autoExecuteTransactions?: boolean to exported NebulaContext type.
UI: context controls, parsing, persistence, propagation
apps/playground-web/src/app/ai/components/ChatPageContent.tsx
Adds user state for wallet address, chain IDs (comma-separated parsed to numeric-like array), and auto-execute checkbox; renders ContextOptionsBar; includes autoExecuteTransactions in derived NebulaContext; persists last-used chain IDs to localStorage and passes updated context to prompt handlers.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant UI as ChatPageContent
  participant Ctx as NebulaContext (derived)
  participant API as chat.ts
  participant Neb as Nebula Server

  U->>UI: Enter wallet, chain IDs, toggle auto-execute
  UI->>UI: derive Ctx { walletAddress, chainIds, autoExecuteTransactions }
  U->>UI: Submit prompt
  UI->>API: sendPrompt(prompt, Ctx)
  API->>API: build body.context with `from` = Ctx.walletAddress and `auto_execute_transactions` = Ctx.autoExecuteTransactions || false
  API->>Neb: POST /chat with body.context
  Neb-->>API: Response
  API-->>UI: Result
  UI-->>U: Display reply
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 227ab57 and ec92a36.

📒 Files selected for processing (2)
  • apps/playground-web/src/app/ai/api/chat.ts (1 hunks)
  • apps/playground-web/src/app/ai/components/ChatPageContent.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/playground-web/src/app/ai/api/chat.ts
  • apps/playground-web/src/app/ai/components/ChatPageContent.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Size
  • GitHub Check: Unit Tests
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cursor/add-chat-context-controls-to-playground-93a7

Comment @coderabbitai help to get the list of available commands and usage tips.

@graphite-app
Copy link
Contributor

graphite-app bot commented Sep 6, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added the Playground Changes involving the Playground codebase. label Sep 6, 2025
@codecov
Copy link

codecov bot commented Sep 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.64%. Comparing base (14fe9ee) to head (ec92a36).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7999   +/-   ##
=======================================
  Coverage   56.63%   56.64%           
=======================================
  Files         904      904           
  Lines       58677    58677           
  Branches     4161     4164    +3     
=======================================
+ Hits        33231    33236    +5     
+ Misses      25340    25335    -5     
  Partials      106      106           
Flag Coverage Δ
packages 56.64% <ø> (+<0.01%) ⬆️
see 3 files with indirect coverage changes
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joaquim-verges joaquim-verges marked this pull request as ready for review September 6, 2025 00:13
@joaquim-verges joaquim-verges requested review from a team as code owners September 6, 2025 00:13
@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 64.01 KB (0%) 1.3 s (0%) 350 ms (+62.27% 🔺) 1.7 s
thirdweb (cjs) 357.32 KB (0%) 7.2 s (0%) 1.7 s (+6.75% 🔺) 8.8 s
thirdweb (minimal + tree-shaking) 5.73 KB (0%) 115 ms (0%) 123 ms (+843.32% 🔺) 237 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 87 ms (+2292.13% 🔺) 97 ms
thirdweb/react (minimal + tree-shaking) 19.15 KB (0%) 383 ms (0%) 137 ms (+345.02% 🔺) 520 ms

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
apps/playground-web/src/app/ai/api/types.ts (1)

37-37: Make the flag non-optional to simplify downstream handling.

Given we always coalesce to a boolean in the payload, consider making this required with a default of false at construction sites to avoid extra undefined checks across the codebase.

-  autoExecuteTransactions?: boolean;
+  autoExecuteTransactions: boolean;
apps/playground-web/src/app/ai/api/chat.ts (1)

25-27: Prefer nullish coalescing and omit nullish fields in the payload.

Use ?? for boolean defaulting and avoid sending null for wallet_address (omit instead), which tends to be cleaner for APIs.

-      wallet_address: params.context.walletAddress,
-      auto_execute_transactions: params.context.autoExecuteTransactions || false,
+      wallet_address: params.context.walletAddress ?? undefined,
+      auto_execute_transactions: params.context.autoExecuteTransactions ?? false,
apps/playground-web/src/app/ai/components/ChatPageContent.tsx (3)

71-76: Harden chain ID parsing and de‑duplicate entries.

Only allow digits, support comma/space separators, and remove duplicates to avoid accidental duplicates or formats like 1e3.

-    const userChainIdArray = userChainIds
-      .split(',')
-      .map(id => id.trim())
-      .filter(id => id !== '' && !isNaN(Number(id)));
+    const userChainIdArray = Array.from(
+      new Set(
+        userChainIds
+          .split(/[,\s]+/)
+          .map((id) => id.trim())
+          .filter((id) => /^\d+$/.test(id)),
+      ),
+    );

125-129: Prefill the options bar from current context for better UX.

Initialize with existing address/chain IDs so users see the active values instead of blanks.

-  const [userWalletAddress, setUserWalletAddress] = useState("");
-  const [userChainIds, setUserChainIds] = useState("");
-  const [userAutoExecute, setUserAutoExecute] = useState(false);
+  const [userWalletAddress, setUserWalletAddress] = useState(address || "");
+  const [userChainIds, setUserChainIds] = useState(
+    (_contextFilters?.chainIds || []).join(", "),
+  );
+  const [userAutoExecute, setUserAutoExecute] = useState(false);

739-796: Conform to design system: remove inline styles, add explicit return type.

  • Use Tailwind width utilities instead of inline style.
  • Add an explicit return type per the TypeScript guideline.
  • Optionally, replace native inputs with @/components/ui/input and a design-system Checkbox/Switch (not shown here to keep the diff minimal).
-function ContextOptionsBar(props: {
+function ContextOptionsBar(props: {
   walletAddress: string;
   chainIds: string;
   autoExecute: boolean;
   onWalletAddressChange: (value: string) => void;
   onChainIdsChange: (value: string) => void;
   onAutoExecuteChange: (value: boolean) => void;
-}) {
+}): React.JSX.Element {
   return (
     <div className="mb-4 rounded-lg border bg-card p-3">
       <div className="flex flex-wrap items-center gap-4">
         <div className="flex items-center gap-2">
           <label htmlFor="wallet-address" className="text-sm font-medium text-muted-foreground">
             Wallet Address:
           </label>
           <input
             id="wallet-address"
             type="text"
             value={props.walletAddress}
             onChange={(e) => props.onWalletAddressChange(e.target.value)}
             placeholder="0x..."
-            className="px-2 py-1 text-sm border border-border rounded focus:outline-none focus:ring-1 focus:ring-ring focus:border-ring bg-background"
-            style={{ width: "200px" }}
+            className="w-[200px] px-2 py-1 text-sm border border-border rounded focus:outline-none focus:ring-1 focus:ring-ring focus:border-ring bg-background"
           />
         </div>
         
         <div className="flex items-center gap-2">
           <label htmlFor="chain-ids" className="text-sm font-medium text-muted-foreground">
             Chain IDs:
           </label>
           <input
             id="chain-ids"
             type="text"
             value={props.chainIds}
             onChange={(e) => props.onChainIdsChange(e.target.value)}
             placeholder="1, 8453"
-            className="px-2 py-1 text-sm border border-border rounded focus:outline-none focus:ring-1 focus:ring-ring focus:border-ring bg-background"
-            style={{ width: "100px" }}
+            className="w-[120px] px-2 py-1 text-sm border border-border rounded focus:outline-none focus:ring-1 focus:ring-ring focus:border-ring bg-background"
           />
         </div>

Follow-up (optional): swap the native <input>s for Input from @/components/ui/input and a DS Checkbox/Switch to fully align with the playground design system.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 14fe9ee and 227ab57.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • apps/playground-web/src/app/ai/api/chat.ts (1 hunks)
  • apps/playground-web/src/app/ai/api/types.ts (1 hunks)
  • apps/playground-web/src/app/ai/components/ChatPageContent.tsx (5 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose

**/*.{ts,tsx}: Use explicit function declarations and explicit return types in TypeScript
Limit each file to one stateless, single‑responsibility function
Re‑use shared types from @/types where applicable
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Prefer composition over inheritance; use utility types (Partial, Pick, etc.)
Lazy‑import optional features and avoid top‑level side‑effects to reduce bundle size

Files:

  • apps/playground-web/src/app/ai/api/types.ts
  • apps/playground-web/src/app/ai/api/chat.ts
  • apps/playground-web/src/app/ai/components/ChatPageContent.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

Files:

  • apps/playground-web/src/app/ai/api/types.ts
  • apps/playground-web/src/app/ai/api/chat.ts
  • apps/playground-web/src/app/ai/components/ChatPageContent.tsx
apps/{dashboard,playground-web}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

apps/{dashboard,playground-web}/**/*.{ts,tsx}: Import UI primitives from @/components/ui/* (Button, Input, Select, Tabs, Card, Sidebar, Badge, Separator) in dashboard and playground apps
Use NavLink for internal navigation with automatic active states in dashboard and playground apps
Use Tailwind CSS only – no inline styles or CSS modules
Use cn() from @/lib/utils for conditional class logic
Use design system tokens (e.g., bg-card, border-border, text-muted-foreground)
Server Components (Node edge): Start files with import "server-only";
Client Components (browser): Begin files with 'use client';
Always call getAuthToken() to retrieve JWT from cookies on server side
Use Authorization: Bearer header – never embed tokens in URLs
Return typed results (e.g., Project[], User[]) – avoid any
Wrap client-side data fetching calls in React Query (@tanstack/react-query)
Use descriptive, stable queryKeys for React Query cache hits
Configure staleTime/cacheTime in React Query based on freshness (default ≥ 60s)
Keep tokens secret via internal API routes or server actions
Never import posthog-js in server components

Files:

  • apps/playground-web/src/app/ai/api/types.ts
  • apps/playground-web/src/app/ai/api/chat.ts
  • apps/playground-web/src/app/ai/components/ChatPageContent.tsx
**/types.ts

📄 CodeRabbit inference engine (AGENTS.md)

Provide and re‑use local type barrels in a types.ts file

Files:

  • apps/playground-web/src/app/ai/api/types.ts
🧬 Code graph analysis (1)
apps/playground-web/src/app/ai/components/ChatPageContent.tsx (1)
apps/playground-web/src/app/ai/api/types.ts (1)
  • NebulaContext (33-38)

@vercel vercel bot temporarily deployed to Preview – nebula September 6, 2025 00:41 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui September 6, 2025 00:41 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb-www September 6, 2025 00:41 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 September 6, 2025 00:41 Inactive
@vercel vercel bot temporarily deployed to Preview – nebula September 6, 2025 00:43 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 September 6, 2025 00:43 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb-www September 6, 2025 00:43 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui September 6, 2025 00:43 Inactive
@joaquim-verges joaquim-verges merged commit a51f4a0 into main Sep 6, 2025
20 of 21 checks passed
@joaquim-verges joaquim-verges deleted the cursor/add-chat-context-controls-to-playground-93a7 branch September 6, 2025 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Playground Changes involving the Playground codebase.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants